import "../modify/index.less";
import { Form, Input, Select, Button, FormProps } from "antd";
import { useTranslation } from "react-i18next";
import { createDictType } from "@/api/system/dict/type";
const { Item } = Form;
const { Option } = Select;
const { TextArea } = Input;
interface TableProps {
	onCancel: () => void;
}
type FieldType = {
	id: number;
	dictionaryName: string;
	dictionaryType: string;
	state?: string;
	notes?: string;
};

const onFinishFailed: FormProps<FieldType>["onFinishFailed"] = errorInfo => {
	console.log("Failed:", errorInfo);
};

const newAdd: React.FC<TableProps> = ({ onCancel }) => {
	const { t } = useTranslation();
	const [form] = Form.useForm();
	const onFinish: FormProps<FieldType>["onFinish"] = values => {
		createDictType(values);
		form.setFieldsValue({});
		onCancel();
	};
	return (
		<>
			<Form form={form} onFinish={onFinish} onFinishFailed={onFinishFailed}>
				<Item
					label={t("system.dict.dictionary_name")}
					name="name"
					className="formItem"
					rules={[{ required: true, message: "Please input your username!" }]}
				>
					<Input></Input>
				</Item>
				<Item
					label={t("system.dict.dictionary_type")}
					name="type"
					className="formItem"
					rules={[{ required: true, message: "Please input your username!" }]}
				>
					<Input></Input>
				</Item>
				<Item label={t("system.dict.state")} name="status" className="formItem">
					<Select>
						<Option value="0">off</Option>
						<Option value="1">on</Option>
					</Select>
				</Item>
				<Item label={t("system.dict.notes")} name="remark" className="formItem">
					<TextArea></TextArea>
				</Item>
				<Item className="formButton">
					<Button>{t("system.dict.cancel")}</Button>
					<Button type="primary" htmlType="submit">
						{t("system.dict.sure")}
					</Button>
				</Item>
			</Form>
		</>
	);
};
export default newAdd;
